package com.higgins.eventtracking.server.projectmanagement;

import java.util.Calendar;
import java.util.Date;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

@PersistenceCapable
public class Effort {
	@SuppressWarnings("unused")
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Long id;
	@Persistent
	private Long parentId;
	@Persistent
	private Date start;
	@Persistent
	private Date stop;
	@Persistent
	private Double duration;
	
	public Effort(Long parentId, Date date)	{
		this.parentId = parentId;
		this.start = date;
	}
	public Effort()	{
	}
	public Long getId()	{
		return id;
	}
	public void setParentId(Long parentId)	{
		this.parentId = parentId;
	}
	public Long getParentId()	{
		return parentId;
	}
	public void setStart(Date start)	{
		this.start = start;
	}
	public Date getStart()	{
		return start;
	}
	public void setStop(Date stop)	{
		setDuration(start, stop);
		this.stop = stop;
	}
	public Date getStop()	{
		return stop;
	}
	public void setDuration(Double duration)	{
		this.duration = duration;
	}
	public Double getDuration()	{
		return duration;
	}
	public void setDuration(Date start, Date stop)	{
		Calendar calStart = Calendar.getInstance();
		Calendar calStop = Calendar.getInstance();
		calStart.setTime(start);
		calStop.setTime(stop);
		double startLong = calStart.getTimeInMillis();
		double stopLong = calStop.getTimeInMillis();
		double difference = stopLong - startLong;
		double seconds = difference/1000;
		double minutes = seconds / 60;
		double hours = minutes / 60;
		duration = hours;
	}
}
